package encounter;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class EncounterServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
        if (user != null) {
            resp.setContentType("text/html");
            resp.getWriter().println("<html>");
            printHeader(resp, "Encounter Aid");
            resp.getWriter().println("<body>");
            resp.getWriter().println("<center>Hello, " + user.getNickname() + "</center>");
            resp.getWriter().println("<hr/>");
            resp.getWriter().println("<div id=\"actions\"></div>");
            resp.getWriter().println("<div id=\"chat\"></div>");
            resp.getWriter().println("<div id=\"stats\"></div>");
            resp.getWriter().println("<div id=\"map\"></div>");
            resp.getWriter().println("<hr/>");
            resp.getWriter().println("</body>");
            resp.getWriter().println("</html>");
        } else {
            resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
        }
	}

	private void printHeader(HttpServletResponse resp, String title) throws IOException {
		resp.getWriter().println("<head>");
		resp.getWriter().println("<title>" + title + "</title>");
		resp.getWriter().println("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\" type=\"text/javascript\"></script>");
		resp.getWriter().println("</head>");
	}
}
